// =================================================================================================
//
//	CopyEngine Framework
//	Copyright 2012 Eran. All Rights Reserved.
//
//	This program is free software. You can redistribute and/or modify infoTree
//	in accordance with the terms of the accompanying license agreement.
//
// =================================================================================================

package app.utils {
    import copyengine.utils.CEStringUtils;

    import flash.utils.Dictionary;

    /**
     * 用于解析SwfInfoTree启动时候的参数 将所有参数用key-value的方式存入字典
     */
    public final class InvokeArgumentManger {
        private static var _instance:InvokeArgumentManger;

        public static function get instance():InvokeArgumentManger {
            if (_instance == null) {
                _instance = new InvokeArgumentManger();
            }
            return _instance;
        }


        private var mArgumentDic:Dictionary;

        public function InvokeArgumentManger() {
        }

        public function initialize(_argumentsArray:Array):void {
            mArgumentDic = new Dictionary();

            if (_argumentsArray != null) {
                for (var i:int = 0; i < _argumentsArray.length; i++) {
                    var key:String = _argumentsArray[i];
                    if (CEStringUtils.beginsWith(key, "-")) {
                        key = CEStringUtils.afterFirst(key, "-");
                        var value:*;
                        if (_argumentsArray[i + 1] == "true" || _argumentsArray[i + 1] == "false") {
                            value = _argumentsArray[i + 1] == "true" ? true : false;
                        }
                        else {
                            value = _argumentsArray[i + 1];
                        }
                    }
                    mArgumentDic[key] = value;
                }
            }
        }

        public function getInvokeArgument(_key:String):* { return mArgumentDic[_key]; }

        public function isContainArgument(_key:String):Boolean { return mArgumentDic[_key] != null }

    }
}
